package it.avantsoft.ls.gl.command;

import it.avantsoft.ls.gl.GroupChildHandler;

/**
 * Created by IntelliJ IDEA.
 * User: blackmore
 * Date: 23-lug-2008
 * Time: 17.46.35
 * To change this template use File | Settings | File Templates.
 */
public class ExchangeHorizontalPeerCommand extends GroupChildCommand {
    private String incomingPeer;
    private String designedGroupLeaderId;

    public ExchangeHorizontalPeerCommand(GroupChildHandler groupChildHandler, String incomingPeer, String designedGroupLeaderId) {
        super(groupChildHandler);
        this.incomingPeer = incomingPeer;
        this.designedGroupLeaderId = designedGroupLeaderId;
    }

    public void execute() {

        GroupChildHandler groupChildHandler = getChild().getChildHandler(designedGroupLeaderId);
        groupChildHandler.sendNewChild(incomingPeer, true);

        getChild().sendAckHorizontalBalance(incomingPeer, groupChildHandler.getHost(), groupChildHandler.getListeningPort());

    }
}
